/**************************************************************************************
 *  Copyright (c)  2010  Pablo Echeverri.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 **************************************************************************************/
package data;

import data.tileables.Laboratory;

public class Technology
{
	private int level;
	private double completion;
	private String name;
	private int max_level;
	private Laboratory lab;
	private double increase_rate;
	private int multiplier;  // every level will give player an improvement of
							 // (level)*(multiplier) 
	
	/**************************************************************************************
	 * Technology being researched
	 **************************************************************************************/

	public Technology(String a_name,int a_max_level, double a_increase_rate, int a_multiplier)
	{
		this.level=0;//some may start at 1
		this.completion=0; //when this reaches 100, increment level
		this.name=a_name;
		this.max_level=a_max_level;
		this.lab=null;
		this.increase_rate=a_increase_rate;
		this.multiplier=a_multiplier;
		
	}
	/**************************************************************************************
	 * Accessor methods
	 **************************************************************************************/

	public Laboratory getLaboratory()
	{
		return this.lab;
	}
	
	public int getCompletion()
	{
		return (int)this.completion;
	}
	
	public int getLevel()
	{
		return this.level;
	}
	
	public String getName()
	{
		return this.name;
	}
	/**************************************************************************************
	 * sets laboratory to given parameter
	 **************************************************************************************/

	public boolean setLaboratory(Laboratory a_lab)
	{
		if(this.lab==null) 
		{
			this.lab=a_lab;
			return true;
		}
		else
		{
			return false;
		}
	}
	/**************************************************************************************
	 * unassigns laboratory from research
	 **************************************************************************************/

	public void removeLaboratory()
	{
		this.lab=null;
		return;
	}
		
	/**************************************************************************************
	 * increases completion percentage of current technology
	 * returns true if technology has reached its max_level
	 **************************************************************************************/
	public boolean increaseCompletion(int numWorkers)
	{
		if(this.level<this.max_level)
		{
			this.completion+=(this.increase_rate)*numWorkers;
			if(this.completion>=100)
			{
				this.level++;
				this.completion=0;
			}
			if(this.level==this.max_level) return true;	
			else return false;
		}
						
		return true;
	}
	
	public int getImprovement()
	{
		return (this.level)*this.multiplier;
	}
		
}